# Maintainer: Dan Printzell <wild@archlinux.org>
# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Contributor: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Contributor: Mihails Strasuns <public@dicebot.lv>

pkgname=dcd
pkgver=0.15.2
pkgrel=1
epoch=1
_pkgcommit=4946d49abdc35810254151923bab30fb3cc2c004
pkgdesc="D Completion Daemon: auto-complete for the D programming language"
arch=('loong64' 'x86_64')
url="https://github.com/dlang-community/DCD"
license=('GPL3')
groups=('dlang')
makedepends=('ldc' 'git')
depends=('liblphobos')
source=("git+https://github.com/dlang-community/DCD#commit=$_pkgcommit"
        "git+https://github.com/msgpack/msgpack-d"
        "git+https://github.com/dlang-community/libdparse"
        "git+https://github.com/dlang-community/d-test-utils"
        "git+https://github.com/dlang-community/containers"
        "dcd.service"
        "dcd.conf")
sha512sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            '563e660058721fdacdfa365a774e58b0e9cdb962e14198112a5d971aa4e35025529266130474212834d78ad1c11901e2f8208176a3891ce6ffc9a2ffd9c8c1e0'
            '1480d4d66b6732f198fcaae52861b06c8bfcee7f622a546d643a4e8fb259aa0350415fb2f87b1bc4d301ad11af866d7962faf2bcfc0587971a86a73265676703')

prepare() {
  cd "$srcdir/DCD"

  git submodule init
  git config submodule.msgpack-d.url "$srcdir/msgpack-d"
  git config submodule.libdparse.url "$srcdir/libdparse"
  git config submodule.d-test-utils.url "$srcdir/d-test-utils"
  git config submodule.containers.url "$srcdir/containers"
  git -c protocol.file.allow=always submodule update

  # Only LDC have -O5
  sed -i "/-O5/ a -flto=full -linker=gold -link-defaultlib-shared=false -L=\"$LDFLAGS\"\\\\" makefile
}

build() {
  cd "$srcdir/DCD"

  make ldc
}

package() {
  # binaries
  install -Dm755 "$srcdir/DCD/bin/dcd-server" "$pkgdir/usr/bin/dcd-server"
  install -Dm755 "$srcdir/DCD/bin/dcd-client" "$pkgdir/usr/bin/dcd-client"

  # documentation
  install -d "$pkgdir/usr/share/man/man1/"
  find "$srcdir/DCD/man1/" -type f -exec install -m 644 "{}" "$pkgdir/usr/share/man/man1/" \;

  # license
  install -Dm644 "$srcdir/DCD/License.txt" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  # systemd service
  install -Dm644 "$srcdir/dcd.service" "$pkgdir/usr/lib/systemd/system/dcd.service"

  # global config
  install -Dm644 "$srcdir/dcd.conf" "$pkgdir/etc/dcd.conf"
}
